package com.maizijinf;

import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * Created by Germmy on 2016/5/14.
 */
public class Producer implements Runnable {

    private BlockingQueue<String> myBq = null;

    public Producer() {

    }

    public Producer(BlockingQueue<String> myBq) {
        this.myBq = myBq;
    }

    public void run() {
        while (true) {
            //每次放10个
            for(int i=0;i<10;i++){
                int tempI = new Random().nextInt(10);
                myBq.add(tempI + "");
                System.out.println(
                        "当前线程ID为:" + Thread.currentThread().getId() +
                                "当前线程Name为:" + Thread.currentThread().getName()
                                + "^_^" + tempI + "已经放入bq中");
            }
            try {
                TimeUnit.MILLISECONDS.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}
